from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver import ActionChains
import time
from selenium.webdriver.common.keys import Keys

driver = webdriver.Chrome("C:\Program Files\driver\chromedriver.exe")
driver.maximize_window()

driver.get("https://www.baidu.com")
time.sleep(3)

# 鼠标移动至设置，出现下拉框
ActionChains(driver).move_to_element(driver.find_element(By.XPATH, "//span[text()='设置']")).perform()

# 点击-搜索设置
driver.find_element(By.XPATH, "//span[text()='搜索设置']/..").click()
time.sleep(2)

# 点击保存设置，出现弹出框
driver.find_element(By.XPATH, "//a[text()='保存设置']").click()

# 获取弹出框内文本信息
print(driver.switch_to.alert.text)
# # 确认弹窗
# driver.switch_to.alert.accept()
# 关闭弹窗
driver.switch_to.alert.dismiss()

time.sleep(3)
driver.quit()